

import 'package:extra_hittest_area/extra_hittest_area.dart';
import 'package:flutter/material.dart';
import 'package:furaha_mkopo/commonTool/fm_screen_tool.dart';

class FMBlockAlertWidget extends Dialog {

  final Widget customWidget;

  const FMBlockAlertWidget({
    super.key,
    required this.customWidget,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Stack(
        fit: StackFit.expand,
        children: [
          //点击半透明区域
          GestureDetector(onTap: () {
            Navigator.pop(context);
          }),
          Center(
            child: ClipRRect(
              borderRadius: const BorderRadius.all(Radius.circular(12)),
              child: SizedBox(
                // decoration: BoxDecoration(
                //   color: GKDThemeColor.of(context).cardColor,
                // ),
                width: FMScreenTool.width(context),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    customWidget,
                    _closeWidget(context)
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _closeWidget(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(top: 16),
      child: GestureDetectorHitTestWithoutSizeLimit(
        extraHitTestArea: const EdgeInsets.all(15),
        onTap: (){
          Navigator.pop(context);
        },
        child: Image.asset("assets/me/pop_close_icon.png",width: 28,height: 28,)
      ),
    );
  }

  static show({
    required BuildContext context,
    required Widget customWidget,
  }) {
    //封装一下 调用系统showDialog方法
    showDialog(
        barrierColor: Colors.black.withOpacity(0.5),
        context: context,
        builder: (context) {
          return FMBlockAlertWidget(
            customWidget: customWidget,
          );
        });
  }

}